package eerbaar.server.statemachine;

public class Transition {

    private final State from;

    private Multiplicity multiplicity = Multiplicity.ONCE;

    private final State to;

    public Transition(State to, State from) {
        this.to = to;
        this.from = from;
        this.multiplicity = Multiplicity.ONCE;
    }

    public Transition(State to, State from, Multiplicity multiplicity) {
        this.to = to;
        this.from = from;
        this.multiplicity = multiplicity;
    }

    @Override
    public boolean equals(Object obj) {
        Transition other = (Transition) obj;
        boolean b1 = other.to.equals(this.to);
        boolean b2 = other.from.equals(this.from);
        return (b1 && b2);
    }

    public State getFrom() {
        return this.from;
    }

    public Multiplicity getMultiplicity() {
        return this.multiplicity;
    }

    public State getTo() {
        return this.to;
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }

    public void incrementMultiplicity() {
        this.multiplicity = Multiplicity.MANY;
    }

    public void setMultiplicity(Multiplicity multiplicity) {
        this.multiplicity = multiplicity;
    }

    public String simpleString() {
        return "(" + this.from.simpleString() + "->" + this.to.simpleString()
                + ")" + ((this.multiplicity == Multiplicity.MANY) ? "*" : "");
    }

    public String string() {
        return "(" + this.from + "->" + this.to + ")"
                + ((this.multiplicity == Multiplicity.MANY) ? "*" : "");
    }

    @Override
    public String toString() {
        return "(" + this.from + "->" + this.to + ")"
                + ((this.multiplicity == Multiplicity.MANY) ? "*" : "");
    }

}
